exports.__esModule = true;

var _assert = require('assert');

var _assert2 = _interopRequireDefault(_assert);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.Service {
    constructor() {
        super();
        this.attachmentModel = this.db['sys_attachment'];
    }

    /**
     * 保存多个文件
     * @param fileArray {Array}　 文件信息
     * @param businesskey {String} 业务主键　
     * @returns {*}
     */
    saveFile(fileArray, businesskey) {
        let arr = [];
        for (let value of fileArray) {
            value.id = think.uuid('v1');
            value.businesskey = businesskey;
            arr.push(value);
        }
        return this.attachmentModel.bulkCreate(arr);
    }
    /**
     * 自定义where查询附件表文件路径
     */
    getFilePath(whereObj) {
        return this.attachmentModel.findAll({
            where: whereObj,
            attributes: ['realpath']
        });
    }

    /**
     * 自定义where删除附件
     * @param whereObj 自定义条件
     * @returns {*}
     */
    delFile(whereObj) {
        (0, _assert2.default)(ObjectUtils.isObject(whereObj), 'object must be a object');
        return this.attachmentModel.destroy({ where: whereObj });
    }
    /**
     * 通过porcid查询案件流程信息
     *
     * @param {any} data  data.id
     * @returns
     */
    getAttByKey(data) {
        var _this = this;

        return _asyncToGenerator(function* () {
            let where = {
                businesskey: data.businesskey
            };
            try {
                const Res = yield _this.attachmentModel.findAll({
                    where: where,
                    attributes: ['realpath']
                });
                return Res;
            } catch (error) {
                return _this.exceptionService.handleError(error);
            }
        })();
    }

};